package org.cpoy.ei.session;

import org.cpoy.eims.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("studentHome")
public class StudentHome extends EntityHome<Student> {

	@In(create = true)
	UserAccountHome userAccountHome;
	@In(create = true)
	CourseHome courseHome;

	public void setStudentId(Integer id) {
		setId(id);
	}

	public Integer getStudentId() {
		return (Integer) getId();
	}

	@Override
	protected Student createInstance() {
		Student student = new Student();
		return student;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		UserAccount userAccount = userAccountHome.getDefinedInstance();
		if (userAccount != null) {
			getInstance().setUserAccount(userAccount);
		}
		Course course = courseHome.getDefinedInstance();
		if (course != null) {
			getInstance().setCourse(course);
		}
	}

	public boolean isWired() {
		if (getInstance().getCourse() == null)
			return false;
		return true;
	}

	public Student getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<StudentPreviousAcadDetails> getStudentPreviousAcadDetailses() {
		return getInstance() == null ? null
				: new ArrayList<StudentPreviousAcadDetails>(getInstance()
						.getStudentPreviousAcadDetailses());
	}

	public List<StudentCerficate> getStudentCerficates() {
		return getInstance() == null ? null : new ArrayList<StudentCerficate>(
				getInstance().getStudentCerficates());
	}

	public List<Parent> getParents() {
		return getInstance() == null ? null : new ArrayList<Parent>(
				getInstance().getParents());
	}

	public List<StudentCertificateLocation> getStudentCertificateLocations() {
		return getInstance() == null ? null
				: new ArrayList<StudentCertificateLocation>(getInstance()
						.getStudentCertificateLocations());
	}

	public List<StudentExtraDetails> getStudentExtraDetailses() {
		return getInstance() == null ? null
				: new ArrayList<StudentExtraDetails>(getInstance()
						.getStudentExtraDetailses());
	}

	public List<StudentEmergencyContact> getStudentEmergencyContacts() {
		return getInstance() == null ? null
				: new ArrayList<StudentEmergencyContact>(getInstance()
						.getStudentEmergencyContacts());
	}

}
